package com.example.wangyi.base;

import java.lang.ref.WeakReference;

import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;

public class BasePresenter<V extends BaseView<T>,T >implements IPersenter<T> {
    private WeakReference<V> mView;
    protected CompositeDisposable mComposite=
            new CompositeDisposable();

    //添加网络开关
    protected void addDisposable(Disposable disposable){
        if (mComposite.add(disposable));

    }

    protected void attachView(V view){
        mView = new WeakReference<V>(view);
    }

    protected void dettachView(){
        if (mView!=null){
            mView.clear();
            mView=null;
        }
        disPosable();
    }

    private void disPosable() {
        if (mComposite!=null&&!mComposite.isDisposed()){
            mComposite.dispose();
            mComposite.clear();
            mComposite = null;
        }
    }

    @Override
    public void start() {

    }

    @Override
    public void start(T... t) {

    }
}
